﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using DevControlLibrary.Common;

namespace DevControlLibrary.UI
{
    /// <summary>
    /// SettingWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SettingWindow 
    {
        public SettingWindow()
        {
            InitializeComponent();
            this.Loaded += SettingWindow_Loaded;
            XmlHelper.Instance.SetTheme(this);
        }

        public 

        void SettingWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.comboBoxFont.ItemsSource = Fonts.SystemFontFamilies;
            this.comboBoxFontSize.ItemsSource = new double[] {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,24,26,28,30,32,34,36,38,40,44,48,52,56,60,64,68,72,76,80,88,96,104,112,120,128,136,144};

            this.comboBoxFont.Text = XmlHelper.Instance.FontName;
            this.comboBoxFontSize.Text = XmlHelper.Instance.FontSize;

            this.tbChDescription.Text = XmlHelper.Instance.ChDescription;

            this.checkFolding.IsChecked = XmlHelper.Instance.IsFloding;

            this.TbMaxCount.Text = XmlHelper.Instance.SelectMaxCount.ToString(CultureInfo.InvariantCulture);

            this.checkVerition.IsChecked = XmlHelper.Instance.IsSimpleControl;

            this.checkBind.IsChecked = XmlHelper.Instance.IsPageBind;

            this.checkShowAutoFilterRow.IsChecked = XmlHelper.Instance.IsShowAutoFilterRow;
        }


        public void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.comboBoxFont.Text != string.Empty)
            {
                XmlHelper.Instance.FontName = this.comboBoxFont.Text;
            }
            if (this.comboBoxFontSize.Text != string.Empty)
            {
                XmlHelper.Instance.FontSize = this.comboBoxFontSize.Text;
            }

            if (checkFolding.IsChecked != null) 
                XmlHelper.Instance.IsFloding = checkFolding.IsChecked.Value;


            if(tbChDescription.Text != string.Empty)
            {
                XmlHelper.Instance.ChDescription = tbChDescription.Text;
            }
            if(TbMaxCount.Text != string.Empty)
            {
                XmlHelper.Instance.SelectMaxCount = Convert.ToDecimal(TbMaxCount.Text);
            }

            if (checkVerition.IsChecked != null) 
                XmlHelper.Instance.IsSimpleControl = checkVerition.IsChecked.Value;

            if(checkBind.IsChecked != null)
                XmlHelper.Instance.IsPageBind = checkBind.IsChecked.Value;

            if (this.checkShowAutoFilterRow.IsChecked != null)
                XmlHelper.Instance.IsShowAutoFilterRow = checkShowAutoFilterRow.IsChecked.Value;

            this.Close();
        }

        public void btnCanel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
